package com.xiaoma.verbal.dao;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;
import com.xiaoma.verbal.baseDao.BaseDaoImpl;
import com.xiaoma.tpo.baseDao.DefaultRowMapper;
import com.xiaoma.verbal.domain.QuQuestion;
import com.xiaoma.verbal.domain.QuTag;
import com.xiaoma.verbal.dto.QuTagVo;

@Repository
public class QuTagDao extends BaseDaoImpl<QuTag> {
	private static final Logger LOG = LoggerFactory.getLogger(QuTagDao.class);

	public List<QuTagVo> findTagByQuestionId(Integer qId) {
		String sql = "SELECT a.tag_id,b.tag_text FROM qu_tag a  left join tag_table b on a.tag_id = b.id  where  a.question_id = ? group by a.tag_id,b.tag_text";
		LOG.info("SQL:{} PARAMS:{}", sql, qId);
		List<?> result = jdbcTemplate.query(sql, new DefaultRowMapper(QuTagVo.class, getNameHandler()), qId);
		return (List<QuTagVo>) result;
	}

	public int deleteByQId(Integer qId) {
		String sql = "DELETE  FROM qu_tag  where  question_id = ?";
		LOG.info("SQL:{} PARAMS:{}", sql, qId);
		return jdbcTemplate.update(sql,qId);
	}
}
